package cn.dyw.cloudmusic.http;

import cn.dyw.cloudmusic.config.MybatisConfig;
import cn.dyw.cloudmusic.dao.LrcMapper;
import cn.dyw.cloudmusic.http.model.Params;
import cn.dyw.cloudmusic.music.vo.MusicLyric;
import com.alibaba.fastjson.JSON;
import okhttp3.Response;
import org.apache.ibatis.session.SqlSession;

/**
 * @author: dyw770
 * @Date: 2019/1/14 23:10
 * @Description: TODO
 */
public class LrcSaveHandle implements SaveHandle {

    @Override
    public void save(Response response, Params p) {
        try {
            MusicLyric musicLyric = JSON.parseObject(response.body().string(), MusicLyric.class);
            SqlSession session = MybatisConfig.getSession();
            LrcMapper mapper = session.getMapper(LrcMapper.class);
            mapper.insertVo(musicLyric.getLrc(), p.songId());
            session.commit();
            session.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
